﻿using BCCommon;
using BCCommon.TMS.FreightEnums;
using BCCommon.TMS.Order;
using BCDto.CRM.BigCustomerFreightConfigExtention;
using BCService.CRM.BigCustomerFreightConfigExtention;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.CRM.BigCustomerFreightConfigExtention
{
    /// <summary>
    /// 大客户运费配置扩展接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BigCustomerFreightConfigExtentionController : ManagementBaseController
    {
        #region var
        private IBigCustomerFreightConfigExtentionService bigCustomerFreightConfigExtentionService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public BigCustomerFreightConfigExtentionController(IBigCustomerFreightConfigExtentionService bigCustomerFreightConfigExtentionService)
        {
            this.bigCustomerFreightConfigExtentionService = bigCustomerFreightConfigExtentionService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新大客户运费配置扩展纪录
        /// </summary>
        /// <param name="dto">大客户运费配置扩展数据模型</param>
        /// <returns></returns>
        [Log("添加新大客户运费配置扩展纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(BigCustomerFreightConfigExtentionRequestDto), 200)]
        public IActionResult Post([FromBody] BigCustomerFreightConfigExtentionRequestDto dto)
        {
            var a = bigCustomerFreightConfigExtentionService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改大客户运费配置扩展纪录
        /// </summary>
        /// <param name="dto">大客户运费配置扩展数据模型</param>
        /// <returns></returns>
        [Log("修改大客户运费配置扩展纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(BigCustomerFreightConfigExtentionPutDto), 200)]
        public IActionResult Put([FromBody] BigCustomerFreightConfigExtentionPutDto dto)
        {
            var a = Ok(bigCustomerFreightConfigExtentionService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除大客户运费配置扩展纪录
        /// </summary>
        /// <param name="bigCustomerFreightConfigExtentionId">大客户运费配置扩展ID</param>
        /// <returns></returns>
        [Log("删除大客户运费配置扩展纪录")]
        [HttpDelete("{big_customer_freight_config_extention_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "big_customer_freight_config_extention_id")] long bigCustomerFreightConfigExtentionId)
        {
            bigCustomerFreightConfigExtentionService.Delete(bigCustomerFreightConfigExtentionId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条大客户运费配置扩展纪录
        /// </summary>
        /// <param name="bigCustomerFreightConfigExtentionId">大客户运费配置扩展ID</param>
        /// <returns></returns>
        [HttpGet("{big_customer_freight_config_extention_id}")]
        [ProducesResponseType(typeof(BigCustomerFreightConfigExtentionDto), 200)]
        public IActionResult Get([FromRoute(Name = "big_customer_freight_config_extention_id")] long bigCustomerFreightConfigExtentionId)
        {
            return (Ok(bigCustomerFreightConfigExtentionService.GetById(bigCustomerFreightConfigExtentionId)));

        }
        #endregion

        #region Query 查询大客户运费配置扩展
        /// <summary>
        /// 查询大客户运费配置扩展
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="vehicleTypeId">车辆类型id</param>
        /// <param name="vehicleCategoryReferenceId">车辆型映射id</param>
        /// <param name="provinceCode">省编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区/县编码</param>
        /// <param name="sourceType">订单来源</param>
        /// <param name="freightType">物流类型</param>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">页数量</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BigCustomerFreightConfigExtentionViewDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "big_customer_id")] long? bigCustomerId,
            [FromQuery(Name = "vehicle_type_id")] int? vehicleTypeId,
            [FromQuery(Name = "vehicle_category_reference_id")] int? vehicleCategoryReferenceId,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "community_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "source_type")] OrderSourceType? sourceType,
            [FromQuery(Name = "freight_type")] FreightType? freightType,
            [FromQuery(Name = "index")] int? pageIndex = 1,
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(bigCustomerFreightConfigExtentionService.GetList(this.Admin, bigCustomerId, vehicleTypeId, vehicleCategoryReferenceId, provinceCode, cityCode, countyCode, sourceType, freightType, pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }

}
